﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_FAQ_ctrFAQCategory : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.InitData(1);
        }
    }
    private void initDataPaging()
    {
        Pager.MaxSmartShortCutCount = 6;
        Pager.NormalModePageCount = 15;
        Pager.SmartShortCutRatio = 3;
        Pager.SmartShortCutThreshold = 30;
        Pager.ItemCount = 0;
        Pager.RTL = false;

        Pager.PageSize = 22;
        Pager.BackToFirstClause = "Về trang đầu";
        Pager.CompactModePageCount = 0;
        Pager.CurrentIndex = 1;
        Pager.FirstClause = "&lt;&lt;";
        Pager.FromClause = "From";
        Pager.GenerateFirstLastSection = false;
        Pager.GenerateGoToSection = false;
        Pager.GenerateHiddenHyperlinks = false;
        Pager.GeneratePagerInfoSection = true;
        Pager.GenerateSmartShortCuts = true;
        Pager.GenerateToolTips = true;

        Pager.GoClause = "go";
        Pager.GoToLastClause = "tới trang cuối";
        Pager.LastClause = "&gt;&gt;";
        Pager.NextClause = "&gt;";
        Pager.NextToPageClause = "Đến trang";
        Pager.OfClause = "trong tổng số";
        Pager.PageClause = "Trang";
        Pager.PreviousClause = "&lt;";
        Pager.QueryStringParameterName = "pagerControlCurrentPageIndex";
        Pager.ShowResultClause = "Từ sản phẩm";
        Pager.ToClause = "đến";
    }
    private void InitData(int CurrentPageIndex)
    {
        int nPageSize = 22;
        int nCat = ConvertData.ConvertToInt(Request.QueryString[Config.FAQ_CAT]);
        if (nCat == 0)
        { nCat = -1; }
        int nPageCount = 0;

        int nCurrentLanguage = Support.GetCurrentLanguage();
        int nDefaultLanguage = Support.GetDefaultLanguage();
        lblFAQ.Text = MultipleLanguage.FAQ[nCurrentLanguage-1];

        try
        {
            DataTable dtb = new DataTable();
            FAQs objFAQ = new FAQs();
            dtb = objFAQ.Search(0, 0, "", nCat, nDefaultLanguage, nCurrentLanguage, EnumeType.ACTIVE, CurrentPageIndex, nPageSize, ref nPageCount);
            dtlFAQByCat.DataSource = dtb;
            dtlFAQByCat.DataBind();
            
            if (nPageCount > 0)
                tblWarning.Visible = false;
            else
                tblWarning.Visible = true;

            Pager.Visible = true;
            VisiblePaging(nPageCount);
            Pager.ItemCount = nPageCount;
        }
        catch
        {
            Response.Redirect("~/Default.aspx");
        }
    }

    protected void dtlFAQByCat_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkQuestion = (HyperLink)e.Item.FindControl("lnkQuestion");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "FAQID"));
            int nCurrentLanguage = Support.GetCurrentLanguage();
            int nDefaultLanguage = Support.GetDefaultLanguage();

            lnkQuestion.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Question"));
            lnkQuestion.NavigateUrl = Config.ROOT + Pages.FrontEnds.FAQ + "?" + Config.FAQ_ID +"=" + nID;
        }
    }
  
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndx = Convert.ToInt32(e.CommandArgument);
        Pager.CurrentIndex = currnetPageIndx;
        this.InitData(currnetPageIndx);
    }

    private void VisiblePaging(int intPagecount)
    {
        int nPageSize = 0;
        nPageSize = 22;
        if (intPagecount > nPageSize)
            Pager.Visible = true;
        else
            Pager.Visible = false;
    }
    protected void dtlFAQByCat_ItemCommand(object source, DataListCommandEventArgs e)
    {

    }
}